package day10;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {

    @org.junit.Test
    public void testInit(){
        List<String> list1=new ArrayList<>();
        list1.add("abc");
        list1.add(0,"def");
        list1.add("lucy");
        list1.add("lucy");
        System.out.println(list1);
        //List<String> list2 = List.of("abc", "def");
        //System.out.println(list2);
        //集合的遍历
        //1. 传统的for循环
        for(int i=0;i<list1.size();i++){
            System.out.print (list1.get(i)+" ");
        }
        System.out.println();

        //2. forEach循环
        for(String data:list1){
            System.out.print(data+" ");
        }
        System.out.println();

        //3. 迭代器
        Iterator<String> iter = list1.iterator();
        while(iter.hasNext()){
            String value=iter.next();
            System.out.print(value+" ");
        }
    }
}
